package edu.ncsu.csc.itrust.beans.loaders;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import edu.ncsu.csc.itrust.beans.PatientReferralBean;

/**
 * A loader for PatientReferralsBeans.
 * 
 * Loads in information to/from beans using ResultSets and PreparedStatements. Use the superclass to enforce consistency. 
 * For details on the paradigm for a loader (and what its methods do), see {@link BeanLoader}
 */

public class PatientReferralBeanLoader implements BeanLoader<PatientReferralBean>{
	
	public List<PatientReferralBean> loadList(ResultSet rs) throws SQLException {
		ArrayList<PatientReferralBean> list = new ArrayList<PatientReferralBean>();
		while (rs.next()) {
			list.add(loadSingle(rs));
		}
		return list;
	}

	public PatientReferralBean loadSingle(ResultSet rs) throws SQLException {
		PatientReferralBean prb = new PatientReferralBean();
		prb.setId(rs.getInt("id"));
		prb.setSenderID(rs.getLong("SenderID"));
		prb.setReceiverID(rs.getLong("ReceiverID"));
		prb.setPatientID(rs.getInt("PatientID"));
		prb.setPriority(rs.getInt("Priority"));
		prb.setOfficeVisitID(rs.getInt("VisitID"));
		prb.setReferralDetails(rs.getString("ReferralDetails"));
		prb.setBeenRead(rs.getInt("Been_Read"));
		prb.setDateAdded(rs.getTimestamp("AddedDate"));

		return prb;
	}

	public PreparedStatement loadParameters(PreparedStatement ps, PatientReferralBean bean) throws SQLException {
		ps.setLong(1, bean.getPatientID());
		ps.setLong(2, bean.getSenderID());
		ps.setLong(3, bean.getReceiverID());
		ps.setLong(4, bean.getOfficeVisitID());
		ps.setInt(5, bean.getPriority());
		ps.setString(6, bean.getReferralDetails());
		ps.setInt(7, bean.getBeenRead());
		ps.setTimestamp(8, bean.getDateAdded());
		return ps;
	}

}
